package erp.education.server.beans.implementation.setup.school;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Component;

import erp.education.client.setup.school.StudentExtraInfoRequest;
import erp.education.server.beans.implementation.BaseService;
import erp.education.server.beans.implementation.ResultResponse;
import erp.education.server.beans.implementation.ServiceObject;
import erp.education.server.beans.interfaces.setup.school.StudentExtraInfoServiceI;
import erp.education.server.beans.interfaces.user.transaction.ServiceObjectI;
import erp.education.server.db.entites.setup.school.StudentExtraInfo;
import erp.education.server.db.exceptions.DbExceptions;

@Component("studentExtraInfoService")
public class StudentExtraInfoService extends BaseService implements
		StudentExtraInfoServiceI {

	@Override
	public ServiceObjectI studentExtraInfoLoadSevice(
			StudentExtraInfoRequest studentExtraInfoRequest)
			throws DbExceptions {
		ServiceObjectI response = new ServiceObject();
		ResultResponse holder = new ResultResponse();
		List result = new ArrayList();

		result.add(studentExtraInfoDao.getStudentExtraInfo());
		holder.setResultList(result);
		response.setResponseObject(holder);
		return response;
	}

	@Override
	public ServiceObjectI saveUpdateStudentExtraInfoDetails(
			StudentExtraInfoRequest studentExtraInfoRequest)
			throws DbExceptions {
		ServiceObjectI response = new ServiceObject();
		ResultResponse holder = new ResultResponse();
		List result = new ArrayList();
		StudentExtraInfo studentExtraInfo = null;
		try {
			studentExtraInfo = studentExtraInfoDao
					.getStudentExtraInfo(studentExtraInfoRequest.getLableName());
		} catch (Exception e) {
		}
		if (null == studentExtraInfo) {
			studentExtraInfo = new StudentExtraInfo();
			studentExtraInfo.setLableName(studentExtraInfoRequest
					.getLableName());

		}
		studentExtraInfo.setInfoType(studentExtraInfoRequest.getInfoType());
		studentExtraInfo.setLableType(studentExtraInfoRequest.getLableType());
		studentExtraInfo.setStatus(studentExtraInfoRequest.getStatus());

		studentExtraInfoDao.merge(studentExtraInfo);

		holder.setResultList(result);
		response.setResponseObject(holder);
		return response;
	}
}
